var isIE=document.all?1:0;


/***
 * Stuff that works with renaming
 ***/
// Conversion of text field into an input field on double click // folder
function update(nn,content) {
    actual = document.getElementById(content);
	elem = actual;
	elem.innerHTML = "<input id=\"updating"+nn+"\" type=\"text\" value=\"" + actual.innerHTML + "\" class=\"updateText\" onkeypress=\"return guardaEnter(this,event," + nn + ")\" onkeyup=\"updateInfo("+nn+")\" onblur=\"return guardaBlur(this," + nn + ")\" />";
	elem.firstChild.focus();
}

//conversion of text field into an input field // page
function updatePage(nn,content) {
    actual = document.getElementById(content);
	elem = actual;
	elem.innerHTML = "<input id=\"updating"+nn+"\" type=\"text\" value=\"" + actual.innerHTML + "\" class=\"updateText\" onkeypress=\"return guardaEnterPage(this,event," + nn + ")\" onkeyup=\"updateInfo("+nn+")\" onblur=\"return guardaBlurPage(this," + nn + ")\" />";
	elem.firstChild.focus();
}

//just duplicate the changes in the right column
function updateInfo(id){
	//rephare the info dings
	var el = document.getElementById("nodeTitle");
	var e2 = document.getElementById("updating"+id);
	el.innerHTML = e2.value;
	return false;
}
/***
 * End Renaming Stuff
 ***/


function showLoad(){
	if(document.getElementById("loadingIC1")){
		document.getElementById("loadingIC1").style.display = '';
	}
}


function hideLoad(){
	if(document.getElementById("loadingIC1")){
		document.getElementById("loadingIC1").style.display = 'none';
	}
}

function display_obtainable_dates(shouldDisplay) {
	
	// method =  ? "enable" : "disable";

	Array("obtainable_Month", "obtainable_Year", "obtainable_Day").each(function(node_name) {
		if (shouldDisplay) {
			document.getElementsByName(node_name)[0].enable();
		} else {
			document.getElementsByName(node_name)[0].disable();
		}
	});
}

/*
 **********************************************************************************************
*/


/***
 * Stuff that shows Node Info And the Tree
 ***/

/*
   Loads the right columns info for a selected folder/node
 */
function showinfo(nn){
    if(!nn){
        nn = null;
    }
    
	//first get the id of the marked node
	var tempElID = getCookie("selected");
    var selectedPage = getCookie("selectedPage");
    
	//unselect Page
	if(tempEl = document.getElementById("sitePage"+selectedPage)){
	  tempEl.style.background = "#fff";   
	}
	
	//try to reset the past selected element to white
	if(tempEl = document.getElementById("siteNode"+tempElID)){
	  tempEl.style.background = "#fff";   
	}
	
	//mark the element
	var el2 = document.getElementById("siteNode"+nn);
	el2.style.background = "#eee";
	
	//now check if this is the same node as the one clicke on again
	if(tempElID != nn){

		showLoad();

	    (new AjaxRequest).send({
    		url			: urlBase+"action=getNodeInfo",
    		data		: {
    			id     : nn
    		},
    		
    		onSuccess	: function(data, info)
    		{
    			document.getElementById("nodeInfo").innerHTML = data["html"];
        		
        		setCookie("selected",nn);
        		setCookie("selectedPage",null);

				hideLoad();
    		}
    	});
	}else{
	    var el2 = document.getElementById("siteNode"+nn);
		el2.style.background = "#eee";
	}
}



/*
   Loads the right columns info for a selected page
 */
function showPageInfo(nn){
    if(!nn){
        nn = null;
    }
    
	//first get the id of the marked node
	var tempElID = getCookie("selectedPage");
	var selectedFolder = getCookie("selected");
    
	//unselect Folder
	if(tempEl = document.getElementById("siteNode"+selectedFolder)){
	  tempEl.style.background = "#fff";   
	}
	
	//try to reset the past selected element to white
	if(tempEl = document.getElementById("sitePage"+tempElID)){
	  tempEl.style.background = "#fff";   
	}
        		
	//mark the element
	var el2 = document.getElementById("sitePage"+nn);
	el2.style.background = "#eee";
		
	//now check if this is the same node as the one clicked on again
	if(tempElID != nn){
	    
		showLoad();

	    (new AjaxRequest).send({
    		url			: urlBase+"action=getPageInfo&id=" + nn,
    		data		: {},
    		
    		onSuccess	: function(data, info)
    		{
    			document.getElementById("nodeInfo").innerHTML = data["html"];
        	
        		setCookie("selectedPage",nn);
	            setCookie("selected",0);

				hideLoad();
    		}
    	});
	}
}

/*
	show input field for enter position of given node. 
*/
function showOrderPositionEdit(node_type, node_id) {
	
	$('orderPos' + node_type + '-' + node_id).hide();
	$('orderPos' + node_type + 'Edit-' + node_id).show();
	$('orderPos' + node_type + 'Edit-' + node_id).focus();
}

/*
	hide input field for enter position of given node. 
*/
function hideOrderPositionEdit(node_type, node_id) {
	
	$('orderPos' + node_type + 'Edit-' + node_id).hide();
	$('orderPos' + node_type + '-' + node_id).show();
}


/*
	call updateOrderPosition function only if ENTER(ASCIICode 13) is pressed 
	within the input field.
*/
function updateOrderPositionOnEnter(note_type,node_id,e) {
	
	// get keycode from javascript event
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	// we only submit if enter is pressed
	// ASCII #13 == ENTER
	if (keycode == 13) {
		updateOrderPosition(note_type,node_id);
	}
}

/*
	submit an ajax request to update the position of this node in the 
	production view (not admin-interface).
	if the ajax request returns Success-Code we hide the input field and
	update the values
*/
function updateOrderPosition(node_type,node_id) {

	// value of position
	var position = $('orderPos' + node_type + 'Edit-' + node_id).value;
	// build url for ajax
	var fetchUrl = 'Change' + node_type + 'OrderPos';
	
	// build ajax request
	(new AjaxRequest).send({
		url			: urlBase+"action="+fetchUrl,
		data		: {
			node_id     : node_id,
			node_type	: node_type,
			position	: position
		},
		
		// on Success we alternate the display and update the values
		onSuccess	: function(data, info)
		{
			$('orderPos' + data.node_type + '-' + data.node_id).innerHTML = data.position;
			hideOrderPositionEdit(data.node_type, data.node_id)
		}
	})
}



/*
   Very important function that loads the actual tree with
   the neccessary sorting options. Will also reset cookies
   in case there is a need to do so
 */
function loadSiteTree(node, sortpref){
    if(node == ''){
        node = getCookie("selected");
    }
    
    //check what sort cookie to choose
    if(sortpref){
        var tempref = getCookie("sorttree");
        
        if(tempref == sortpref){    // we are in the same column
        
            var tempsortdir = getCookie("sorttreedir");
            
            if(tempsortdir == "asc"){
                setCookie("sorttreedir","desc","/");    
            }else{
                setCookie("sorttreedir","asc","/");    
            }
            
        }else{ //changing column
            setCookie("sorttree",sortpref,"/");  
            setCookie("sorttreedir","asc","/");    
        }
    }
    
	showLoad();

    //reset the probable parent cookie
    setCookie("probableParent",node,"/");   
    setCookie("selectedPage",null);
    setCookie("selected",null);
    
    //loadXMLDoc(urlBase + "action=getNodeTree&id="+escape(node),"nodeTree");
    //alert(urlBase);
    //urlBase = 'admin/sitestructure/ajax/?';
    //alert(urlBase+"action=getNodeInfo");
    
    (new AjaxRequest).send({
		url			: urlBase+"action=getNodeTree",
		data		: {
			id : node
		},
		
		onSuccess	: function(data, info)
		{

			document.getElementById("nodeTree").innerHTML = data["html"];
			
			showLoad();
			
			(new AjaxRequest).send({
        		url			: urlBase+"action=getNodeInfo",
        		data		: {
        			id      : node,
        			nodel   : true
        		},
        		
        		onSuccess	: function(data, info)
        		{
        			document.getElementById("nodeInfo").innerHTML = data["html"];
            		
            		setCookie("selected",null);
            		setCookie("selectedPage",null);
        		}
        	});
        	
        	hideLoad();
		}
	});
	
}
/***
 * End Stuff That Shows Node Info
 ***/



/*
 **********************************************************************************************
*/


/*
 ---------------------- FOLDERZ ------------------------
 |
*/

/* ############## ADD ######################################################### */

function checkEnter(element, evt, id, tempId, type){
    evt = (evt) ? evt : window.event;

	if (evt.keyCode == 13 && element.value!="") {	// pressed enter!
        createNode(element,id,tempId,type);
	}else{
	    return true;
	}
}


var ajaxConnection = false;
function createNode(element,parentID,tempId,type){
    var elem = document.getElementById("newFolder"+tempId);
    var orderPos = 0;
    
    if (window.enable_order_position){
        orderPos = $("orderPosNodeEdit-"+tempId).value;
	}

    showLoad();
    if(!ajaxConnection) {
    	ajaxConnection = true;
	    (new AjaxRequest).send({
			url			: urlBase+"action=addNode",
			data		: {
				title  : element.value,
				ntype  : type,
				parent : parentID,
				porderPos : orderPos
			},
		
			onSuccess	: function(data, info) {
				elem.innerHTML = data["html"];
				elem.id = "node"+data["newID"];
			
				var pubstate = document.getElementById("newNodePubState");
				pubstate.innerHTML = "<div class=\"unpublished\" onClick=\"publishNode("+data["newID"]+")\">&nbsp;</div>";
				pubstate.id = 'p_node'+data["newID"];
			
				//reset the row id to match the other stuff =)
				//document.getElementById("freshFolder").id = "node"+data["newID"];
            
				//fade away the input box
				Fat.fade_element("node"+data["newID"],10,1000,"#ffffcc","#ffffff");

				hideLoad();
	            ajaxConnection = false;
			}
		});
	}
}

function addFolderAlt(id) {
    
    // determine unique ID for a minute
	var currentTime = new Date();
	var tempId = currentTime.getMinutes()+''+currentTime.getSeconds()+''+currentTime.getMilliseconds();
	

    //make sure only one folder can be added at a time ;)
    if(!document.getElementById('newFolderName')){
        //hide empty folder note
        if(document.getElementById("emptyFolder")){
            document.getElementById("emptyFolder").style.display = "none";
        }
        
        //get type
        var type    =   document.getElementById('folderType').value;
        
        //mark the selection for the future
        setCookie("folderType",type,"/"); 
        
        //add new row to table
	    // var myRows  =   document.getElementById('ssTableContent').rows.length;
	    if(document.getElementById('FolderFilesSeperator')){
	        var seperator = document.getElementById('FolderFilesSeperator').rowIndex;
	    }else{
	        var seperator = document.getElementById('ssTableContent').rows.length;
	    }
        var myTable =   document.getElementById('ssTableContent').insertRow(seperator);

        
        myTable.id  =   'freshFolder';

        insertCellCounter = 0;
        
        if (window.enable_order_position) {
            
    		var myCellPos = myTable.insertCell(insertCellCounter); insertCellCounter++;			        
    		myCellPos.align = "right";
    		myCellPos.innerHTML    = "<input onKeyPress=\"updateOrderPositionOnEnter('Node'," + tempId + ",event)\"" +
    		        "class=\"orderPos textinput\" " +
    		        "style=\"display:none;  text-align:right;\" " +
    		        "type=\"text\" " +
    		        "name=\"order_pos\" " +
    		        "value=\"...\" " +
    		        "id=\"orderPosNodeEdit-" + tempId +"\" " +
    		        "size=\"2\"> " +
    					"<span   ondblclick=\"showOrderPositionEdit('Node', '" + tempId + "');\" " +
    					        "class=\"nodeOrderText\" id=\"orderPosNode-" + tempId + "\">0</span>";
        }
        var myCell  =   myTable.insertCell(insertCellCounter); insertCellCounter++;
        myCell.innerHTML    = "<div class=\"folder newstuff\" id=\"newFolder"+tempId+"\"><input type=\"text\" name=\"title\" id=\"newFolderName\" value=\"\" onkeypress=\"return checkEnter(this,event,"+id+","+tempId+","+type+")\" class=\"updateText\" onblur=\"return createNode(this,"+id+","+tempId+","+type+");\" /></div>";
        document.getElementById('newFolderName').focus();
        
        
        //figure out the requested type
        var sopt    =   document.getElementById('folderType').options;
        var seli    =   document.getElementById('folderType').selectedIndex
        
        var myCellS  =   myTable.insertCell(insertCellCounter); insertCellCounter++;
        myCellS.innerHTML = "<div class=\"unpublished\">&nbsp;</div>";
        myCellS.id   = 'newNodePubState';
        
        var myCell2  =   myTable.insertCell(insertCellCounter); insertCellCounter++;
        myCell2.innerHTML   = sopt[seli].label;
        
        //figure out the last mod date
        var today = new Date()
        var day   = today.getDate();
        if(day < 10){
            day = "0"+day;
        }
        
        var month = today.getMonth() + 1;
        if(month < 10){
            month = "0"+month;
        }
        
        var year  = today.getFullYear();   
        var hours = today.getHours();
        if(hours < 10){
            hours = "0"+hours;
        }
        
        var min   = today.getMinutes();
        if(min < 10){
            min = "0"+min;
        }
        
        var myCell3  =   myTable.insertCell(insertCellCounter);
        myCell3.innerHTML   = day + "/" + month + "/" + year + " " + hours + ":" + min;
        
        //hide confirmation dialogs
        hide('confirm');

		// fetch and assign next order position
		if (window.enable_order_position){
		    fetchNextOrderPosition("orderPosNode",id,tempId,'folder');
		}
	    
    }
    return false;
}


/* ############## EDIT ######################################################### */

//saving the converted text field after enter was pressed
function guardaEnter(campo,evt,idfld) {
	evt = (evt) ? evt : window.event;

	if (evt.keyCode == 13 && campo.value!="") {	// pressed enter!
		ajaxUpdateNode(idfld, campo.value);
		return false;
	} else {
		return true;
	}
}

//saving the converted text field after mouse was clicked away
function guardaBlur(campo,idfld) {
	if (campo.value!="") {
		ajaxUpdateNode(idfld, campo.value);
		return false;
	}
}



function ajaxUpdateNode(id,value){
	showLoad();
    (new AjaxRequest).send({
		url			: urlBase+"action=updateNode",
		data		: {
			id : id,
			value : value
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("siteNode"+id).innerHTML = data["html"];
			hideLoad();
		}
	});
}


/* ############## DELETE ######################################################### */

function dropNode(id,myMessage){
    if(confirm(myMessage)){
        showLoad();

		deleteme('siteNode'+id);

        (new AjaxRequest).send({
    		url			: urlBase+"action=dropNode",
    		data		: {
    			id : id
    		},
    		
    		onSuccess	: function(data, info)
    		{
    			document.getElementById("nodeInfo").innerHTML = data["html"];
				hideLoad();
				hide('node'+id);
    		}
    	});

    }
    return false;
}


/* ############## PUBLISH ######################################################### */

function publishNode(id){
	showLoad();
    (new AjaxRequest).send({
		url			: urlBase+"action=publishNode",
		data		: {
			id : id
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("p_node"+id).innerHTML = data["html"];
			hideLoad();
		}
	});
	 
    return false;
}

function unPublishNode(id){
	showLoad();
    (new AjaxRequest).send({
		url			: urlBase+"action=unPublishNode",
		data		: {
			id : id
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("p_node"+id).innerHTML = data["html"];
			hideLoad();
		}
	});
	
    return false;
}
/*
 |
 ---------------------------------------------------------------
*/


/*
 **********************************************************************************************
*/


/*
 ---------------------- PAGEZ --------------------------
 |
*/

/* ############## ADD ######################################################### */

/*
 Function checks whether while adding a new folder the enter key was hit
*/
function checkEnterPage(element, evt, id, tempId, type){
    evt = (evt) ? evt : window.event;

	if (evt.keyCode == 13 && element.value!="") {	// pressed enter!
		createPage(element,id, tempId,type);
	}else{
		return true;
	}
}


function createPage(element, parentID, tempId, type){
    var elem = document.getElementById("newPage"+tempId);
    var orderPos = 0;
    
    if (window.enable_order_position){
        orderPos = $("orderPosNodeEdit-"+tempId).value;
	}

    showLoad();
    if(!ajaxConnection){
    ajaxConnection = true;
    (new AjaxRequest).send({
		url			: urlBase+"action=addPage",
		data		: {
			title  : element.value,
			ptype  : type,
			parent : parentID,
			porderPos : orderPos 
		},
		
		onSuccess	: function(data, info)
		{
			elem.innerHTML = data["html"];
			
			var pubstate = document.getElementById("newPagePubState");
			pubstate.innerHTML = "<div class=\"unpublished\" onClick=\"publishPage("+data["newID"]+")\">&nbsp;</div>";
			pubstate.id = 'p_page'+data["newID"];
			
			//reset the id to match the overall structure
			elem.id = "page"+data["newID"];
			//document.getElementById("freshPage").id = "page"+data["newID"];

			Fat.fade_element(elem.id,10,1000,"#ffffcc","#ffffff");

			hideLoad();
            ajaxConnection = false;
		}
	});
    }
}


/*
 Advanced Add Page
*/
function addPageAlt(id) {
	
	var currentTime = new Date();
	var tempId = currentTime.getMinutes()+''+currentTime.getSeconds()+''+currentTime.getMilliseconds();
	
	
    //make sure only one folder can be added at a time ;)
    if(!document.getElementById('newPageName')){
        //hide empty folder note
        if(document.getElementById("emptyFolder")){
            document.getElementById("emptyFolder").style.display = "none";
        }
        
        //get type
        var type    =   document.getElementById('pageType').value;
        
        //mark the selection for the future
        setCookie("pageType",type,"/");
        
        //add new row to table
	    var myRows  =   document.getElementById('ssTableContent').rows.length;
        var myTable =   document.getElementById('ssTableContent').insertRow(myRows)
        
        myTable.id  =   "freshPage";
        
        
        insertCellCounter = 0;
        
        if (window.enable_order_position) {
    		var myCellPos = myTable.insertCell(insertCellCounter); insertCellCounter++;	
    		myCellPos.align = "right";
    		myCellPos.innerHTML    = "<input onKeyPress=\"updateOrderPositionOnEnter('Node'," + tempId + ",event)\"" +
    		        "class=\"orderPos textinput\" " +
    		        "style=\"display:none\" " +
    		        "type=\"text\" " +
    		        "name=\"order_pos\" " +
    		        "value=\"...\" " +
    		        "id=\"orderPosNodeEdit-" + tempId +"\" " +
    		        "size=\"2\"> " +
    					"<span   ondblclick=\"showOrderPositionEdit('Node', '" + tempId + "');\" " +
    					        "class=\"nodeOrderText\" id=\"orderPosNode-" + tempId + "\">...</span>";
		}
				
        var myCell  =   myTable.insertCell(insertCellCounter); insertCellCounter++;	
        myCell.innerHTML    = 	"<div class=\"page newstuff\" style=\"background-color: #ffc;\" id=\"newPage"+tempId+"\">" + 
									"<input type=\"text\" name=\"title\" id=\"newPageName\" value=\"\" onkeypress=\"return checkEnterPage(this,event,"+id+","+tempId+","+type+")\" class=\"updateText\" onblur=\"return createPage(this,"+id+","+tempId+","+type+")\" />"+
								"</div>";
        document.getElementById('newPageName').focus();
        
        
        //figure out the requested type
        var sopt    =   document.getElementById('pageType').options;
        var seli    =   document.getElementById('pageType').selectedIndex
        
        var myCellS  =   myTable.insertCell(insertCellCounter); insertCellCounter++;	
        myCellS.innerHTML = "<div class=\"unpublished\">&nbsp;</div>";
        myCellS.id   = 'newPagePubState';
        
        var myCell2  =   myTable.insertCell(insertCellCounter); insertCellCounter++;	
        myCell2.innerHTML   = sopt[seli].label;
        
        //figure out the last mod date
        var today = new Date()
        var day   = today.getDate();
        if(day < 10){
            day = "0"+day;
        }
        
        var month = today.getMonth() + 1;
        if(month < 10){
            month = "0"+month;
        }
        
        var year  = today.getFullYear();   
        var hours = today.getHours();
        if(hours < 10){
            hours = "0"+hours;
        }
        
        var min   = today.getMinutes();
        if(min < 10){
            min = "0"+min;
        }
        
        var myCell3  =   myTable.insertCell(insertCellCounter); insertCellCounter++;	
        myCell3.innerHTML   = day + "/" + month + "/" + year + " " + hours + ":" + min;
        
        //hide confirmation dialogs
        hide('confirm');

		// fetch and assign next order position
		if (window.enable_order_position){
		    fetchNextOrderPosition("orderPosNode",id,tempId,'page')
		}
    }
    return false;
}

// fetch and assign next order position
function fetchNextOrderPosition(idPrefix,parentID,elemID,objectType) {
	(new AjaxRequest).send({
		url			: urlBase+"action=nextOrderPosition",
		data		: {
			scope : parentID,
			otype : objectType
			
		},

		onSuccess	: function(data, info)
		{
			// write nextPosition in the view
			document.getElementById(idPrefix+"-"+elemID).innerHTML = data["nextPosition"];
			document.getElementById(idPrefix+"Edit-"+elemID).value = data["nextPosition"];
		}
	});
}


/* ############## UPDATE ######################################################### */

//saving the converted text field after enter was pressed
function guardaEnterPage(campo,evt,idfld) {
	evt = (evt) ? evt : window.event;

	if (evt.keyCode == 13 && campo.value!="") {	// pressed enter!
	    
	    ajaxUpdatePage(idfld,campo.value);
	   		
		return false;
	} else {
		
		return true;
	}
}

//saving the converted text field after mouse was clicked away
function guardaBlurPage(campo,idfld) {
	if (campo.value!="") {
	    
	    ajaxUpdatePage(idfld,campo.value);
	    
		return false;
	}
}


function ajaxUpdatePage(id,value){
	showLoad();
    (new AjaxRequest).send({
		url			: urlBase+"action=updatePage",
		data		: {
			id : id,
			value: value
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("sitePage"+id).innerHTML = data["html"];
			
			hideLoad();
		}
	});
}


/* ############## DELETE ######################################################### */

function dropPage(id,myMessage){
    if(confirm(myMessage)){
		showLoad();

		deleteme('sitePage'+id);

        (new AjaxRequest).send({
    		url			: urlBase+"action=dropPage",
    		data		: {
    			id : id
    		},
    		
    		onSuccess	: function(data, info)
    		{
    			document.getElementById("nodeInfo").innerHTML = data["html"];
    			Fat.fade_element("page"+id,10,1000,"#ffffff","#ff0000");
				hideLoad();
				hide('page'+id);
    		}
    	});
    }
    return false;
}


/* ############## COPY ######################################################### */

function copyPage(id,myMessage){

	(new AjaxRequest).send({
   		url			: urlBase+"action=copyPage",
   		data		: {
   			id : id
   		},
   		
   		onSuccess	: function(data, info)
   		{
   			Element.insert('ssTableContent', {bottom : data["html"]});
			updatePage(data['id'],'pageRow' + data['id']);
   		}
   	});
    return false;
}

/* ############## CLONE ######################################################### */

function clonePage(id){
	
	(new AjaxRequest).send({
   		url			: urlBase+"action=clonePage",
   		data		: {
   			id : id
   		},
   		
   		onSuccess	: function(data, info)
   		{
			Element.insert('ssTableContent', {bottom : data["html"]});
			updatePage(data['id'],'pageRow' + data['id']);
   		}
   	});
	return false;
}

/* ############## PUBLISH ######################################################### */

function publishPage(id){
    (new AjaxRequest).send({
		url			: urlBase+"action=publishPage",
		data		: {
			id : id
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("p_page"+id).innerHTML = data["html"];
		}
	});
	
    return false;
}

function unPublishPage(id){
    (new AjaxRequest).send({
		url			: urlBase+"action=unPublishPage",
		data		: {
			id : id
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("p_page"+id).innerHTML = data["html"];
		}
	});
	
    return false;
}

/*
 |
 ----------------------------------------------------------------
*/


function loadPageEdit(id){
    if(isIE){
        window.location.href = '?action=edit&id='+id;
    }else{
        window.location.href = 'sitestructure/?action=edit&id='+id;
    }
    return;
}


function loadNodeEdit(id){
    if(isIE){
        window.location.href = '?action=edit&node='+id;
    }else{
        window.location.href = 'sitestructure/?action=edit&node='+id;
    }
    return;
}

/* ---------- OPENING AND CLOSING OPTIONS DIALOGS --------------- */
function closeDialog(id){
    unhide(id+'_alt');

	var myEl = document.getElementById(id+'_data');
	new Effect.Fade(myEl,{duration:0.3});
	new Effect.BlindUp(myEl,{duration:0.3});

    //hide(id+'_data'); 
    hide(id); 
    setCookie('close_'+id,1,"/");
}

function openDialog(id){
	var myEl = document.getElementById(id+'_data');
	new Effect.Appear(myEl,{duration:0.3});
	new Effect.BlindDown(myEl,{duration:0.3});

    //unhide(id+'_data'); 
    unhide(id); 
    hide(id+'_alt');   
    setCookie('close_'+id,0,"/");
}



function changeURL(oid,otype,oldurl){

    if(newName = prompt('Please enter new URL',oldurl)){
        showLoad();
        (new AjaxRequest).send({
            url			: urlBase+"action=changeURL",
            data		: {
                id : oid,
                type : otype,
                name : newName
            },
            
            onSuccess	: function(data, info)
            {
                document.getElementById("CHPU").innerHTML = data["html"];
                hideLoad();
            }
        });
	}
}